<?php
namespace application\controllers;

use system\core\Controller;
use application\models\UsersTable;

class Users extends Controller
{
    /**
     * Index Action
     */
    public function index()
    {
        
    }
    
    /**
     * Login Action
     */
    public function login()
    {
        $this->template->disable();
        
        $data = array(
            'role'       => 'user',
            'logged_in'  => TRUE
        );
        
        $this->session->setData($data);
        
        echo 'Ingelogd!';
    }
    
    /**
     * Logout Action
     */
    public function logout()
    {
        $this->template->disable();
        $this->session->destroy();
        echo 'Uitgelogd!';
    }
    
    /**
     * Edit Action
     * 
     * @param int $id
     */
    public function edit( $id = NULL )
    {
        $usersTable = new UsersTable();
        
        // Find a user and store him in the $data array
        $data['user'] = $usersTable->find($id);
        
        // Update user
        $usersTable->username = 'newUsernsame';
        $usersTable->password = 'newPdassword';
        $usersTable->update($id);
        
        echo $usersTable->rowCount();
        
        // Load the vars in the Registry
        $this->load->vars($data);
        
        // Disable the template auto rendering
        $this->template->disable();
        
        // Now Hosselaar only loads the users/edit view, because we disabled
        // the template rendering.
        $this->load->view('users/edit', $data);
    }
    
    /**
     * News Action
     */
    public function news()
    {
        $newsModel = new \Application\Models\NewsModel();
        
        $newsModel->getAllUsers();
        
        $this->template->disable();
    }
}

/* End of file Info.php */